import * as types from './types.js'

import { getUserInfo } from '@/services/services_user'

export default {
  namespaced: true,
  state: {
    currentRoute: '/',
    token: '',
    userId: '',
    userInfo: {},
    userCount: 0
  },
  mutations: {
    changeRoute (state, context) {
      state.currentRoute = context
    },
    // 更新通证
    updateToken (state, context) {
      state.token = context
    },
    // 更新用户id
    updateUserId (state, context) {
      state.userId = context
    },
    // 更新当前用户信息
    updateUserInfo (state, context) {
      state.userInfo = context
    },
    // 更新当前用户邀请人数
    updateUserCount (state, context) {
      state.userCount = context
    },
  },
  actions: {
    async getUserInfo (context, payload) {
      const res = await getUserInfo(payload)
      if (res.code != 0) {
        // Toast(res.msg);
      } else {
        context.commit('updateUserInfo', res.data)
      }
    }
  },
  getters: {
  }
}
